package demo.controller;


import demo.BlogContentApi;
import demo.pojo.AddBlogInfoRequest;
import demo.pojo.BlogInfoResponse;
import demo.pojo.UpBlogRequest;
import demo.common.pojo.BlogInfo;
import demo.pojo.response.Result;
import demo.server.BlogService;
import jakarta.validation.Valid;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@Slf4j
@RequestMapping("/blog-content")
@RestController
public class BlogController implements BlogContentApi {
    @Autowired
    private BlogService blogService;

    @Override
    public Result<List<BlogInfoResponse>> getList() {
        return Result.success(blogService.getList());
    }

    @Override
    public Result<BlogInfoResponse> getBlogDetail(@NotNull Integer blogId) {
        log.info("getBlogDetail, blogId: {}", blogId);
        return Result.success(blogService.getBlogDetail(blogId));
    }

    @Override
    public Result<Boolean> addBlog(@Validated AddBlogInfoRequest addBlogInfoRequest) {
        log.info("addBlog 接收参数: "+ addBlogInfoRequest);
        return Result.success(blogService.addBlog(addBlogInfoRequest));
    }

    @Override
    public Result<Boolean> updateBlog(@Valid UpBlogRequest upBlogRequest) {
        log.info("updateBlog 接收参数: "+ upBlogRequest);
        return Result.success(blogService.update(upBlogRequest));
    }

    @Override
    public Result<Boolean> deleteBlog(@NotNull Integer blogId) {
        log.info("deleteBlog 接收参数: "+ blogId);
        return Result.success(blogService.delete(blogId));
    }
}
